const express = require("express");
const { async } = require("validate.js");
const router = express.Router();
const { addBlogServices, getPageBlogServices, deleteBlogServices, updateBlogServices, getBlogOneServices } = require("../services/blogServices");
// 添加文章
router.post("/", async (req, res, next) => {
    res.send(await addBlogServices(req.body));
})

// 分页获取文章
router.get("/", async (req, res, next) => {
    res.send(await getPageBlogServices(req.query));
})

// 删除一篇文章
router.delete("/:id", async (req, res, next) => {
    res.send(await deleteBlogServices(req.params.id));
})

// 修改一篇文章
router.put("/:id", async (req, res, next) => {
    res.send(await updateBlogServices(req.params.id, req.body));
})

// 获取单篇文章
router.get("/:id", async (req, res, next) => {
    res.send(await getBlogOneServices(req.params.id))
})

module.exports = router;